#include "Method.h"

const double L = 10;
const double r = 1;
const double V = 12.4;

double f(double h){
  double tmp = r*r;
  return L*(0.5*PI*tmp - tmp*asin(h/r) - h*sqrt(tmp - h*h)) - V;
}


double df(double h){
  return -2*L*sqrt(r*r-h*h);
}

int main(int argc, char* argv[]){
  double (*pf)(double) = &f;
  double (*pdf)(double) = &df;
  double result,error = 0;
  Bisection<double> BstSolver(100,0.01,pf,0,r,1e-8);
  if (BstSolver.Is_proper()){
    result = BstSolver.solve();
    error = (*pf)(result);
    cout << "Bisection method: depth = " << r - result << ", absolute error = " << error << endl;
  }
  else
    cout << "Problem 1: Error! The problem is not proper!" << endl;
  Newton<double> NTSolver(50,0.01,pf,pdf,0.5);
  result = NTSolver.solve();
  error = (*pf)(result);
  cout << "Newton method: depth = " << r - result << ", absolute error = " << error << endl;
  Secant<double> SCSolver(50,0.01,pf,0.5,0.6,1e-8);
  result = SCSolver.solve();
  error = (*pf)(result);
  cout << "Secant method: depth = " << r - result << ", absolute error = " << error << endl;
}
